<%@ Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" Codefile="EditNews.aspx.vb" Inherits="EditNews" %>
<%@ Register TagPrefix="wu" TagName="PictureUpload" Src="../PictureUpload.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="server">


    <asp:sqldatasource id="SqlDataSource1" runat="server" providername="<%$ ConnectionStrings:WroxUnited.ProviderName %>"
        selectcommand="SELECT [NewsID], [DateToShow], [Description], [PictureURL], [Category], [Title] FROM [News] ORDER BY [DateToShow] DESC"
        connectionstring="<%$ ConnectionStrings:WroxUnited %>">
    </asp:sqldatasource>

    <asp:gridview id="GridView1" runat="server" datakeynames="NewsID" datasourceid="SqlDataSource1"
        autogeneratecolumns="False"
        allowpaging="True" allowsorting="True" OnRowDataBound="GridView1_RowDataBound">
        <SelectedRowStyle CssClass="rowSelected" />
        <EmptyDataTemplate>
            There are no news items - please click the Add News button.
        </EmptyDataTemplate>
        <Columns>
            <asp:CommandField ShowSelectButton="True"></asp:CommandField>
            <asp:BoundField ReadOnly="True" HeaderText="NewsID" DataField="NewsID" SortExpression="NewsID" Visible="False"></asp:BoundField>
            <asp:BoundField HeaderText="Show After" DataField="DateToShow" SortExpression="DateToShow" DataFormatString="{0:dd MMM yyyy}"></asp:BoundField>
            <asp:BoundField HeaderText="Category" DataField="Category" SortExpression="Category"></asp:BoundField>
            <asp:BoundField HeaderText="Title" DataField="Title" SortExpression="Title"></asp:BoundField>
        </Columns>
    </asp:gridview>
    <asp:LinkButton id="AddNew" runat="server" onClick="AddNew_Click" Text="Add News" />

    <br /><br />
    <asp:sqldatasource id="SqlDataSource2" runat="server"
        ConnectionString="<%$ ConnectionStrings:WroxUnited %>"
        SelectCommand="SELECT * FROM [News] WHERE ([NewsID] = @NewsID)"
        UpdateCommand="UPDATE [News] SET [DateToShow] = @DateToShow, [Description] = @Description, [PictureURL] = @PictureURL, [Category] = @Category, [Title] = @Title WHERE [NewsID] = @NewsID"
        InsertCommand="INSERT INTO [News] ([DateToShow], [Description], [PictureURL], [Category], [Title]) VALUES (@DateToShow, @Description, @PictureURL, @Category, @Title)"
        DeleteCommand="DELETE FROM [News] WHERE [NewsID] = NewsID"
        OnDeleted="SqlDataSource2_Deleted" OnInserted="SqlDataSource2_Inserted" OnUpdated="SqlDataSource2_Updated">
        <DeleteParameters>
            <asp:Parameter Type="Int32" Name="original_NewsID"></asp:Parameter>
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Type="DateTime" Name="DateToShow"></asp:Parameter>
            <asp:Parameter Type="String" Name="Description"></asp:Parameter>
            <asp:Parameter Type="String" Name="PictureURL"></asp:Parameter>
            <asp:Parameter Type="String" Name="Category"></asp:Parameter>
            <asp:Parameter Type="String" Name="Title"></asp:Parameter>
            <asp:Parameter Type="Int32" Name="NewsID"></asp:Parameter>
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter Name="NewsID" Type="Int32" ControlID="GridView1" PropertyName="SelectedValue"></asp:ControlParameter>
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Type="DateTime" Name="DateToShow"></asp:Parameter>
            <asp:Parameter Type="String" Name="Description"></asp:Parameter>
            <asp:Parameter Type="String" Name="PictureURL"></asp:Parameter>
            <asp:Parameter Type="String" Name="Category"></asp:Parameter>
            <asp:Parameter Type="String" Name="Title"></asp:Parameter>
        </InsertParameters>
        </asp:sqldatasource>
        <asp:detailsview id="DetailsView1" runat="server" datasourceid="SqlDataSource2" DataKeyNames="NewsID" AutoGenerateRows="False">
        <Fields>
            <asp:BoundField Visible="False" ReadOnly="True" HeaderText="NewsID" InsertVisible="False" DataField="NewsID" SortExpression="NewsID"></asp:BoundField>
            <asp:BoundField HeaderText="Date To Show" DataField="DateToShow" SortExpression="DateToShow"></asp:BoundField>
            <asp:BoundField HeaderText="Category" DataField="Category" SortExpression="Category"></asp:BoundField>
            <asp:BoundField HeaderText="Title" DataField="Title" SortExpression="Title"></asp:BoundField>
            <asp:TemplateField HeaderText="Description">
                <HeaderStyle VerticalAlign="Top"></HeaderStyle>
                <EditItemTemplate>
                    <asp:TextBox id="TextBox1" runat="server" Text='<%# Bind("Description") %>' Columns="50" Rows="10" TextMode="MultiLine"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("Description") %>' id="Label1"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField SortExpression="PictureURL" HeaderText="PictureURL">
                <EditItemTemplate>
                    <asp:TextBox id="TextBox2" runat="server" Text='<%# Bind("PictureURL") %>'></asp:TextBox>
                    <wu:PictureUpload id="PictureUpload1" runat="server" UploadImageType="News"
                        OnFileUploaded="FileUploaded"></wu:PictureUpload> 
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("PictureURL") %>' id="Label2"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowInsertButton="True" ShowDeleteButton="True" ShowEditButton="True"></asp:CommandField>
        </Fields>
    </asp:detailsview>
    
</asp:Content>
